﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JChatCore.Log;
using JChatData.LogMap;
using JChatData.Helper;
namespace JChatSerVices.LogServices
{
   public partial class LogService:ILogService
    {
       DBConectString _db;
      // ChatModel _context;
       GetConnect.GetFileConnect _get;
       public LogService()
       {
           _get = new GetConnect.GetFileConnect();
           string file = _get.GetFile("conn");
           _db = new DBConectString(file);
         
       }

       #region Get Data

       public List<Log> GetAllLog()
       {
           var log = (from l in _db._context.JChat_Log
                      select l).ToList();
           return log;

       }
       public List<Log> GetLogByID(int id)
       {
           var log = (from l in _db._context.JChat_Log
                      where l.LogID ==id
                      select l).ToList();
           return log;

       }
       #endregion

       #region Add / Update / Delete
       
       public bool AddLog(Log _log)
       {
           try
           {
               _db._context.JChat_Log.AddObject(_log);
               _db._context.SaveChanges();
               return true;
           }
           catch
           {
               return false;
           }
       }
       public bool Update(int _id, Log _logtable)
       {

           try
           {
               var _log = (from l in _db._context.JChat_Log
                          where l.LogID == _id
                          select l).SingleOrDefault();
               _log.LogText = _log.LogText;
               _db._context.SaveChanges();
               return true;
           }
           catch
           {
               return false;
           }
       }
       
       public bool Delete (int _id)
       {
           try
           {
               var _log = (from l in _db._context.JChat_Log
                          where l.LogID == _id
                          select l).SingleOrDefault();
               _db._context.DeleteObject(_log);
               _db._context.SaveChanges();
               return true;
           }
           catch
           {
               return false;
           }
       }
       #endregion
    }
}
